//
//  MainheadView.m
//  liangyi
//
//  Created by 张水 on 17/1/16.
//  Copyright © 2017年 yswh. All rights reserved.
//

#import "MainheadView.h"
#import "AppHeader.h"
@interface MainheadView ()<SDCycleScrollViewDelegate>

@property (nonatomic, copy  ) NSArray *arrCycleData;

@property(nonatomic,strong) SDCycleScrollView * cycleView;

@end

@implementation MainheadView


-(instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    
    if (self){
    
        [self setup];
    }
    return  self;
}

-(void)setup{
    
    self.cycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0,kScreenWidth, 160) delegate:self placeholderImage:[UIImage imageNamed:@""]];
//    self.cycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenWidth, 160) shouldInfiniteLoop:YES imageNamesGroup:@[@"banner",@"banner",@"banner"]];
    self.cycleView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    self.cycleView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
    self.cycleView.pageDotColor = [UIColor ColorWithHex:@"#5bc4d2"];
    self.cycleView.autoScrollTimeInterval = 3.0;
    [self addSubview:self.cycleView];
    
}

- (void)getScrollImageNetwork {
    
    NSString *url = [BASEURL stringByAppendingString:KURL_CycleImage];
    
    [AppNetwork requestWithPath:url parameters:nil success:^(id responseObject) {
        DDLOG(@"cycle image %@", responseObject);
        NetworkModel *network = [NetworkModel mj_objectWithKeyValues:responseObject];
        NSLog(@"%@",network);
        if (network.code.integerValue == 0) {
            if ([network.dataObject isKindOfClass:[NSArray class]]) {
                NSArray *arr = [ScrollImageModel mj_objectArrayWithKeyValuesArray:network.dataObject];
                self.arrCycleData = [arr copy];
                NSMutableArray *mArr = [NSMutableArray new];
                for (ScrollImageModel *model in arr) {
                    [mArr addObject:[NSString stringWithFormat:@"%@/%@",BaseIamgeUrl,model.slideUrl]];
                }
                self.cycleView.imageURLStringsGroup = [mArr copy];
            }
        }
    } failure:^(id error) {}];
}



@end
